@include('common.header')
<link rel="stylesheet" href="{{ asset('/css/list.css') }}" />


<script>


	// 点击发工资时
	function gongzi( admin_id,admin_name )
	{
		// 标题
		$("#gongzi").html("发工资 : "+admin_name);
		// 属性
		$("#gongzi").attr("admin_id",admin_id);
	}
	
	
	// 点击日志时
	function liulan( admin_id,admin_name )
	{
		// 标题
		$("#liulanModalLabel").html("工资记录 : "+admin_name);
		// 获取记录
		$.ajax({
			type:"post",
			url:"{{ url('/getPayLog') }}",
			data:{admin_id:admin_id,_token:_token},
			async:true,    					
			dataType:"html",
			success:function(back)
			{
				$("#modal-body").html('');
				$("#modal-body").append(back);
			}
		});
	}

</script>


<div class="row" style="width:100%;margin-top:6%;" >
	<div class="col-md-12" style="text-align:center;" >
		<!-- 页面标记 -->
		<b style="font-size:22px;color:#32CD32;" >工资列表</b>
	</div>
</div>


<!-- 职工表格 -->
<!-- class="bs-example" -->
<div  class="wrap" style="width:90%;margin-top:2%;" >
	<!-- class="table table-hover" -->
    <table class="listtab" >
		<thead>
			<tr>
				<th></th>
				<th>编号</th>
				<th>职工</th>
				<th>基本工资</th>
				<th>补助</th>
				<th>绩效</th>
				<th>扣除</th>
				<th>实际发放</th>
				<th>日期</th>
				<th>每月10号</th>
				<th>发放</th>
			</tr>
		</thead>
		<tbody>
			@forelse($admin as $key=> $admin_info)
				<tr>
					<td></td>
					<td>{{ $admin_info->id }}</td>
					<td>{{ $admin_info->name }}</td>
					<td>{{ $latest[$admin_info->id]['base'] }}</td>
					<td>{{ $latest[$admin_info->id]['subsidy'] }}</td>
					<td>{{ $latest[$admin_info->id]['performance'] }}</td>
					<td>{{ $latest[$admin_info->id]['cut'] }}</td>
					<td>{{ $latest[$admin_info->id]['total'] }}</td>
					<td>{{ $latest[$admin_info->id]['at'] }}</td>
					<td>
						<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#gongziModal" data-whatever="@mdo" onclick="gongzi({{ $admin_info->id }},'{{ $admin_info->name }}');" >
							发工资
						</button>
					</td>
					<td>
						<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#liulanModal" onclick="liulan({{ $admin_info->id }},'{{ $admin_info->name }}');" >
							日志
						</button>
					</td>
				</tr>
			@empty
				<tr>
					<td scope="row"><h2>暂无数据</h2></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
				</tr>
			@endforelse
		</tbody>
    </table>
</div>


<!-- 日志模态框 -->
<div class="modal fade" id="liulanModal" tabindex="-1" role="dialog" aria-labelledby="liulanModalLabel">
	<div class="modal-dialog" role="document" style="top:10%;" >
		<div class="modal-content">
			
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
				<h4 class="modal-title" id="liulanModalLabel" liulanid="" >发放记录</h4>
			</div>
			<div class="modal-body" id="modal-body" style="height:auto;display:block;" >
				
				<!-- class="popover fade right in" -->
				<!-- <div class="arrow" style="top: 50%;"></div> -->
				
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
			</div>
		</div>
	</div>
</div>


<!-- 工资模态框 -->
<div class="modal fade" id="gongziModal" tabindex="-1" role="dialog" aria-labelledby="gongziModalLabel" >
	<div class="modal-dialog" role="document" style="top:3%;">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
				<h4 class="modal-title" id="gongzi" admin_id='' ></h4>
			</div>
			<div class="modal-body" style="height:200px;" >
				<form>
					<div class="form-group" style="float:left;width:260px;margin-right:20px;">
						<label for="recipient-name" class="control-label">底薪 :
							<!-- 快捷选择  -->
							<div class="btn-group" data-toggle="buttons">
								<label class="btn btn-info active" style="margin-left:20px;margin-right:20px;width:70px;border-radius:10px 10px 10px 10px;" onclick="$('#base').val('2500');" >
									<input type="radio" name="options" id="option1" autocomplete="off" checked>
									2500
								</label>
								<label class="btn btn-info" style="margin-right:20px;width:70px;border-radius:10px 10px 10px 10px;" onclick="$('#base').val('3500');"  >
									<input type="radio" name="options" id="option2" autocomplete="off">
									3500
								</label>
								
							</div>
						</label>
						<input type="text" class="form-control" id="base" value="" >
					</div>
					
					<div class="form-group" style="width:260px;float:left;">
						<label for="message-text" class="control-label" >补贴 :
							<!-- 快捷选择  -->
							<div class="btn-group" data-toggle="buttons">
								<label class="btn btn-warning" style="margin-left:20px;margin-right:20px;width:70px;border-radius:10px 10px 10px 10px;" onclick="$('#subsidy').val('100');"  >
									<input type="radio" name="options" id="option3" autocomplete="off">
									100
								</label>
								<label class="btn btn-warning" style="margin-right:20px;width:70px;border-radius:10px 10px 10px 10px;" onclick="$('#subsidy').val('300');"  >
									<input type="radio" name="options" id="option4" autocomplete="off">
									300
								</label>
							</div>
						</label>
						<input type="text" class="form-control" id="subsidy">
						<!--<textarea class="form-control" id="message-text"></textarea>-->
					</div>
					
					<div class="form-group" style="width:260px;float:left;margin-right:20px;">
						<label for="message-text" class="control-label">绩效 :
							<!-- 快捷选择  -->
							<div class="btn-group" data-toggle="buttons">
								<label class="btn btn-warning" style="margin-left:20px;margin-right:20px;width:70px;border-radius:10px 10px 10px 10px;" onclick="$('#performance').val('100');"  >
									<input type="radio" name="options" id="option5" autocomplete="off">
									100
								</label>
								<label class="btn btn-warning" style="margin-right:20px;width:70px;border-radius:10px 10px 10px 10px;" onclick="$('#performance').val('300');"  >
									<input type="radio" name="options" id="option6" autocomplete="off">
									300
								</label>
							</div>
						</label>
						<input type="text" class="form-control" id="performance">
					</div>
					
					<div class="form-group" style="width:260px;float:left;">
						<label for="message-text" class="control-label">扣款 :
							<!-- 快捷选择  -->
							<div class="btn-group" data-toggle="buttons">
								<label class="btn btn-danger" style="margin-left:20px;margin-right:20px;width:70px;border-radius:10px 10px 10px 10px;" onclick="$('#cut').val('10');"  >
									<input type="radio" name="options" id="option7" autocomplete="off">
									10
								</label>
								<label class="btn btn-danger" style="margin-right:20px;width:70px;border-radius:10px 10px 10px 10px;" onclick="$('#cut').val('50');"  >
									<input type="radio" name="options" id="option8" autocomplete="off">
									50
								</label>
							</div>
						</label>
						<input type="text" class="form-control" id="cut">
					</div>
					
					<div class="motai" style="position:fixed;width:300px;height:40px;background:red;display:none;top:4%;left:35%;z-index:1000;text-align:center;color:#fff;font-size:17px;line-height:42px;border-radius:10px 10px 10px 10px;" ></div>
					
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				<button type="button" class="btn btn-primary" id="gong" >发放</button>
			</div>
		</div>
	</div>
</div>


<!-- 分页 -->
<div style='text-align:center;'>
	{{ $admin->links() }}
</div>
<div class="badge" style="width:100%;text-align:center;font-size:18px;margin-bottom:70px;margin-top:20px;" >
		共{{ $admin->total() }}条数据
</div>


<script>
	
	$(function()
	{
		
		function showDiv(info)
		{
			$(".motai").html(info);
			$(".motai").slideDown(1000);
			$(".motai").delay(1500).slideUp(1000);
		}
		
		// 发放工资
		$("#gong").click(function()
		{
			// 员工id
			var admin_id = $("#gongzi").attr("admin_id");
			// 底薪
			var base = $("#base").val();
			// 补贴
			var subsidy = $("#subsidy").val();
			// 绩效
			var performance = $("#performance").val();
			// 扣款
			var cut = $("#cut").val();
			// 正则 为整数 1到5位
			var reg = /^[\d]{1,5}$/;
			if( !reg.test(base) || base <= '0' || base== '' )
			{
				showDiv('请输入底薪');
				return false;
			}
			if( subsidy!= '' )
			{
				if( !reg.test(subsidy) || subsidy <= '0' )
				{
					showDiv('请输入补贴');
					return false;
				}
			}
			if( performance!= '' )
			{
				if( !reg.test(performance) || performance <= '0' )
				{
					showDiv('请输入绩效');
					return false;
				}
			}
			if( cut!= '' )
			{
				if( !reg.test(cut) || cut <= '0' )
				{
					showDiv('请输入扣款');
					return false;
				}
			}
			$.ajax({
				type:"post",
				url:"{{ url('/payOff') }}",
				data:{base:base,subsidy:subsidy,performance:performance,cut:cut,admin_id:admin_id,_token:_token},
				async:true,    					
				dataType:"json",
				success:function(back)
				{
					showDiv(back['show_info']);
					if( back['show_info'].indexOf("成功") > 0 )
					{
						setTimeout(function(){
							window.location.href="{{ url('/boss') }}";
						},2500);
					}
				}
			});
		});
	});
	
</script>


@extends('common.footer')

